package com.hyts.sdkhttp.domain;

import com.alibaba.fastjson.JSONObject;
import com.hyts.sdkhttp.constant.CharacterEncoding;
import com.hyts.sdkhttp.constant.ContentType;
import com.hyts.sdkhttp.constant.RequestMethod;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;

import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.SocketAddress;

/**
 * project-name:iscloud
 * package-name:com.ultrapower.zq.domain
 * author:Libo/Alex
 * create-date:2018-03-12 9:53
 * copyright:libo-hyts-github
 * email:libo2dev@aliyun.com
 * description:此类主要用于: sdk 客户端请求操作请求服务类
 */
@Builder
@AllArgsConstructor
public class SdkRequest {

    /**
     * url请求操作路径服务 * 必填
     */
    private String url;

    /**
     * request请求方法类型：默认为GET：选填
     */
    private RequestMethod requestMethod = RequestMethod.GET;

    /**
     * 字符编码参数 : 默认为UTF-8：选填
     */
    private CharacterEncoding charset = CharacterEncoding.UTF_8;
    
    /**
     * 默认模拟编码方式的提交以及encode编码：选填
     */
    private ContentType contentType = ContentType.FORM_URLENCODE_DATA;
    
    /**
     * 请求头 - 请求头：选填
     */
    private JSONObject header;

    /**
     * 请求参数 - 请求参数：选填
     */
    private JSONObject params;
    
    /**  
     * @Fields field:field:{todo}(用一句话描述这个变量表示什么)  
     */ 
    private Proxy proxy;
    
    /**
     * 是否维护长连接:默认为true：选填
     */
    private boolean isConnectionKeepAlive = true;
    
	/**  
	 * @return url  
	 */
	public String getUrl() {
		return url;
	}

	/**  
	 */
	public void setUrl(String url) {
		this.url = url;
	}

	/**  
	 * @return requestMethod  
	 */
	public RequestMethod getRequestMethod() {
		return requestMethod;
	}

	/**  
	 */
	public void setRequestMethod(RequestMethod requestMethod) {
		this.requestMethod = requestMethod;
	}

	/**  
	 * @return header  
	 */
	public JSONObject getHeader() {
		return header;
	}

	/**  
	 */
	public void setHeader(JSONObject header) {
		this.header = header;
	}

	/**  
	 * @return params  
	 */
	public final JSONObject getParams() {
		return params;
	}

	/**  
	 */
	public final void setParams(JSONObject params) {
		this.params = params;
	}

	/**  
	 * @return charset  
	 */
	public CharacterEncoding getCharset() {
		return charset;
	}

	/**  
	 */
	public void setCharset(CharacterEncoding charset) {
		this.charset = charset;
	}

	/**  
	 * @return contentType  
	 */
	public ContentType getContentType() {
		return contentType;
	}

	/**  
	 */
	public void setContentType(ContentType contentType) {
		this.contentType = contentType;
	}

	/**  
	 * @return isConnectionKeepAlive  
	 */
	public boolean isConnectionKeepAlive() {
		return isConnectionKeepAlive;
	}

	/**  
	 */
	public void setConnectionKeepAlive(boolean isConnectionKeepAlive) {
		this.isConnectionKeepAlive = isConnectionKeepAlive;
	}
	
	public void setProxy(Proxy proxy) {
	        this.proxy = proxy;
	}

	public void setProxy(String host, int port, Proxy.Type type) {
	        SocketAddress addr = new InetSocketAddress(host, port);
	        this.proxy = new Proxy(type, addr);
	}

	/**  
	 * @constructor：SdkRequest  
	 * @param url  
	 */ 
	
	
	public SdkRequest(String url) {
		super();
		this.url = url;
	}

	/**  
	 * @constructor：SdkRequest    
	 */ 
	
	
	public SdkRequest() {
		super();
	}

	/**  
	 * @constructor：SdkRequest  
	 * @param url
	 * @param requestMethod  
	 */ 
	
	
	public SdkRequest(String url, RequestMethod requestMethod) {
		super();
		this.url = url;
		this.requestMethod = requestMethod;
	}

	/**  
	 * @constructor：SdkRequest  
	 * @param url
	 * @param requestMethod
	 * @param charset  
	 */ 
	
	
	public SdkRequest(String url, RequestMethod requestMethod, CharacterEncoding charset) {
		super();
		this.url = url;
		this.requestMethod = requestMethod;
		this.charset = charset;
	}
	
	
}
